import axios from '~/plugins/axios';

import * as types from '../../mutation-types/unread-news/index';

export const getUnreadNewsList = ({commit, state}, preload) => {
    axios.get('http://122.224.223.246:28080/app/pubInfo.action', {
        params: preload
    })
        .then((response) => {
            if (!response) {
                return
            }
            if (response.data && response.data.data) {
                commit(types.UNREAD_NEWSLIST, {
                    unreadNewsList: response.data.data
                });
                commit(types.UNREAD_NEWSLIST_CURRENTPAGE, {
                    currentPage: response.data.pageno
                });
                commit(types.UNREAD_NEWSLIST_TOTALCOUNT, {
                    totalCount: response.data.maxpage * 15
                });
            }
        })
};

export const getReceiverList = ({commit, state}, preload) => {
    axios.get('http://122.224.223.246:28080/app/pubInfo.action', {
        params: preload
    })
        .then((response) => {
            if (!response) {
                return
            }
            if (response.data && response.data.data) {
                commit(types.RECEIVER_LIST, {
                    receiverList: response.data.data
                });
                commit(types.RECEIVER_LIST_CURRENTPAGE, {
                    receiverCurrentPage: response.data.pageno
                });
                commit(types.RECEIVER_LIST_TOTALCOUNT, {
                    receiverTotalCount: response.data.maxpage * 15
                });
            }
        })
};